import 'dart:ui' as ui;

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_app/base/const_color.dart';

class ThirdWidget extends StatefulWidget {
  @override
  _ThirdWidgetState createState() => _ThirdWidgetState();
}

class _ThirdWidgetState extends State<ThirdWidget> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: SizedBox(
          width: 200,
          height: 200,
          child: CustomPaint(
            painter: Sky(),
            child: Center(
              child: Text(
                'Once upon a time...',
                style: const TextStyle(
                  fontSize: 40.0,
                  fontWeight: FontWeight.w900,
                  color: Color(0xFFFFFFFF),
                ),
              ),
            ),
          ),
        ),
      )
    );
  }
}

class IndexBar extends CustomPainter{

  @override
  void paint(Canvas canvas, Size size) {
    Paint paint = new Paint();
    paint.color = themeColor;
    paint.isAntiAlias = true;
    canvas.drawPaint(paint);
  }

  @override
  bool shouldRepaint(CustomPainter oldDelegate) {
    // TODO: implement shouldRepaint
    return null;
  }

}

class Sky extends CustomPainter {
  ui.Image image;
  @override
  void paint(Canvas canvas, Size size) {
    canvas.drawImage(
           image,
            Offset.zero,
             Paint()..imageFilter = ui.ImageFilter.blur(sigmaX: .5, sigmaY: .5),
          );
  }

  ///
  @override
  SemanticsBuilderCallback get semanticsBuilder {
    return (Size size) {
      // Annotate a rectangle containing the picture of the sun
      // with the label "Sun". When text to speech feature is enabled on the
      // device, a user will be able to locate the sun on this picture by
      // touch.
      var rect = Offset.zero & size;
      var width = size.shortestSide ;
      rect = const Alignment(-0.5,0.5).inscribe(Size(width, width), rect);
      return [
        CustomPainterSemantics(
          rect: rect,
          properties: SemanticsProperties(
            label: 'Sun',
            textDirection: TextDirection.ltr,
            hint: "hello,canvas",
            onTap: (){
              debugPrint("button");
            }
          ),
        ),
      ];
    };
  }

  @override
  bool shouldRepaint(CustomPainter oldDelegate) {
    // TODO: implement shouldRepaint
    return false;
  }
}